package b2.widget
{
	import b2.config.*;
	import b2.player.*;
	import b2.net.*;
	import b2.util.*;
	import b2.scene.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.net.*;
	import flash.text.*;
	import flash.geom.Point;
	import flash.ui.Mouse;

	public class TankPicIcon extends Sprite
	{
		private var tankId:int;
		private var tankMessage:TankMessage;
		
		public function TankPicIcon(tankId:int)
		{
			super();
			this.tankId = tankId;
			var tankInfo:TankInfo = PlayerInfoManager.getInstance().tanks[tankId];
			var TankPicPaneBgr:Class = ResourceHelper.getInstance().getClassByName("TankPicPaneBgr");
			var tankPicPaneBgr:Sprite = new TankPicPaneBgr();
			addChild(tankPicPaneBgr);
			var tankConfig:TankConfig = Config.objectConfigs[tankInfo.index];
			var TankIcon:Class = ResourceHelper.getInstance().getClassByName(tankConfig.iconImage);
			var tankIcon:Sprite = new TankIcon();
			//齐天大圣
			if (tankConfig.index == 10015)
			{
				tankIcon.width = 82;
				tankIcon.height = 92;
			}
			//死亡骑士
			else if (tankConfig.index == 10020)
			{
				tankIcon.width = 72;
				tankIcon.height = 72;
			}
			else
			{
				tankIcon.width = 60;
				tankIcon.height = 60;
			}
			tankPicPaneBgr.addChild(tankIcon);
			addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			addEventListener(MouseEvent.CLICK, onMouseClick);
		}
		
		private function onMouseClick(event:MouseEvent):void
		{
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
			this.filters = [new ColorMatrixFilter(BFont.brightFilter)];
			if (tankMessage == null)
			{
				var globalPoint:Point = this.parent.localToGlobal(new Point(this.x, this.y));
				tankMessage = new TankMessage(tankId);
				tankMessage.x = globalPoint.x + this.width;
				tankMessage.y = globalPoint.y;
				SceneManager.getInstance().currentScene.addChild(tankMessage);
			}
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
			this.filters = null;
			if (null != tankMessage && null != tankMessage.parent)
        	{
        		tankMessage.parent.removeChild(tankMessage);
        		tankMessage = null;
        	}
		}
	}
}